package com.work.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.function.Function;

@Getter
@AllArgsConstructor
public enum UserClockRecordType {
    //    年
    YEAR(v -> String.format("YEAR(%s)", v), v -> formatTime(v, "yyyy")),
    //    月
    MONTH(v -> "DATE_FORMAT(" + v + ",'%Y-%m')", v -> formatTime(v, "yyyy-MM"));

    private final Function<String, String> fn;
    private final Function<LocalDateTime, String> date;

    private static String formatTime(LocalDateTime time, String format) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);

        return time.format(formatter);
    }
}
